package cn.edu.hpu.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.hpu.dao.ContactDao;
import cn.edu.hpu.entity.Contact;
import cn.edu.hpu.entity.Project;
import cn.edu.hpu.utitl.UUIDUtitl;

public class EditContactServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");
		String cname = request.getParameter("cname");
		String ccompany = request.getParameter("ccompany");
		String cmobile = request.getParameter("cmobile");
		String cphoto = request.getParameter("cphone");
		String cmail = request.getParameter("cmail");
		String caddress = request.getParameter("caddress");
		String cweb = request.getParameter("cweb");
		String cb = request.getParameter("cb");
		String ca = request.getParameter("ca");
		String cblog = cb.concat(ca);
		String  cintroduce = request.getParameter("cintroduce");
		String cid = request.getParameter("cid");
		HttpSession session = request.getSession();
		Project p = (Project)session.getAttribute("project");
		String pid = p.getPid();
		Contact c = new Contact();
		c.setCaddress(caddress);
		c.setCblog(cblog);
		c.setCcompany(ccompany);
		c.setCid(cid);
		c.setCintroduce(cintroduce);
		c.setCmail(cmail);
		c.setCmobile(cmobile);
		c.setCname(cname);
		c.setCphoto(cphoto);
		c.setCweb(cweb);
		c.setPid(pid);
		ContactDao cd = new ContactDao();
		try {
			cd.updatecontact(c);
			List<Contact> list = cd.findAllByPid(pid);
			request.setAttribute("clist", list);
			request.getRequestDispatcher("/WEB-INF/views/contact.jsp").forward(request, response);
		} catch (Exception e) {
			response.sendRedirect("index.jspx");
		}
	}
		
}

